package com.zgc.demo.ftzf.config;

import dev.miku.r2dbc.mysql.MySqlConnectionFactoryProvider;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
import org.springframework.data.r2dbc.core.DatabaseClient;

import static io.r2dbc.spi.ConnectionFactoryOptions.*;
import static io.r2dbc.spi.ConnectionFactoryOptions.PORT;

@Configuration
public class R2dbcConfig extends AbstractR2dbcConfiguration {
    @Bean
    @Override
    public ConnectionFactory connectionFactory() {
        return new MySqlConnectionFactoryProvider().create(
                ConnectionFactoryOptions.builder()
                        .option(DRIVER, "mysql") //
                        .option(USER, "root") //
                        .option(PASSWORD, "root") //
                        .option(DATABASE, "testdb") //
                        .option(HOST, "localhost") //
                        .option(PORT, 3306) //
                        .build()
        );
    }

// 不用创建  DatabaseClient 单列bean了。因为他已经创建了。
//    @Bean
//    public DatabaseClient databaseClient() {
//
//    }


}
